package com.geeker.module.sys.dept.controller;

import com.geeker.common.annotation.PreAuth;
import com.geeker.common.api.CommonResult;
import com.geeker.common.util.PageUtil;
import com.geeker.module.sys.dept.domain.SysDept;
import com.geeker.module.sys.dept.dto.SysDeptDto;
import com.geeker.module.sys.dept.service.SysDeptService;
import com.mybatisflex.core.paginate.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Tag(name = "部门信息")
@RequestMapping("/sys/dept")
public class SysDeptController {

    @Autowired
    private SysDeptService sysDeptService;

    @Operation(summary = "分页")
    @PostMapping("page")
    public CommonResult<Page<SysDept>> page(@RequestBody SysDeptDto dto) {
        Page<SysDept> page = PageUtil.getPage(dto);
        Page<SysDept> iPage = sysDeptService.page(page);
        return CommonResult.success(iPage);
    }

    @Operation(summary = "详情")
    @PostMapping("detail/{deptId}")
    @PreAuth(value = "sys:dept:detail")
    public CommonResult<SysDept> detail(@PathVariable Integer deptId) {
        return CommonResult.success(sysDeptService.getById(deptId));
    }

    @Operation(summary = "删除")
    @PostMapping("delete/{deptId}")
    @PreAuth(value = "sys:dept:delete")
    public CommonResult<Boolean> delete(@PathVariable Integer deptId) {
        return CommonResult.success(sysDeptService.removeById(deptId));
    }
}
